﻿<!--#include file="../../lib/base.asp"-->
<!--#include file="../../theme/admin/config.asp"-->
<!--#include file="../../lib/cmd.asp"-->
<%
''' SDCMS 蜘蛛来访插件
''' ==================================================================
''' 版权所有 http://www.sdcms.cn
''' ------------------------------------------------------------------
''' 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用；
''' 未经授权不允许对程序代码以任何形式任何目的的再发布。
''' ==================================================================
''' 插件编写: IT平民
''' 修改：IT平民 in 2012.12

	'注释：插件是否安装
	is_plug_install "sdcms.plug.spider"
	
	'注释：下面是接收处理程序
	dim spider_name:spider_name=getspider
	if sdcms.strlen(spider_name)<=0 then sdcms.die
	
	'注释：检查缓存
	if not(sdcms.checkcache("spider_"&spider_name,0)) then
		spiderdb(spider_name)
		sdcms.setcache "spider_"&spider_name,spider_name,0
	end if
	
	function getspider()
		dim agent:agent=request.servervariables("http_user_agent")
		if agent="" then
			getspider=""
			exit function
		end if
		dim str01,str02
		str01=split("Baidu|Google|archiver|ASPSeek|Yahoo|sohu|MSNBOT|360","|")
		str02=split("Baidu|Google|Alexa|ASPSeek|Yahoo|SOHU|MSN|360","|")
		dim i
		for i=0 to ubound(str01)
			if instr(lcase(agent),lcase(str01(i)))>0 then
				getspider=str02(i)
				exit function
			end if
		next
		getspider=""
	end function
	
	sub spiderdb(byval t0)
		dim rs
		set rs=server.createobject("adodb.recordset")
		rs.open "select spider,hits,lastupdate from sd_plug_spider where spider='"&t0&"'",sdcms.db.conn,1,3
		if rs.eof then
			rs.addnew
			rs(0)=t0
			rs(1)=1
			rs(2)=now()
		else
			rs.update
			rs(1)=rs(1)+1
			rs(2)=now()
		end if
		rs.update
		rs.close
		set rs=nothing
	end sub
%>